#include "btfrom.h"
#include "ui_btfrom.h"
#include <QMouseEvent>


BTFrom::BTFrom(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BTFrom)
{
    ui->setupUi(this);

    ui->lineBox->hide();

   this->animal1 = new QPropertyAnimation(ui->line1,"geometry",this);
   this->animal1->setDuration(1500);
   this->animal1->setStartValue(QRect(6,20,3,0));
   this->animal1->setKeyValueAt(0.5,QRect(6,0,3,20));
   this->animal1->setEndValue(QRect(6,20,3,0));

   this->animal1->setLoopCount(-1);
   this->animal1->start();

    this->animal2 = new QPropertyAnimation(ui->line2,"geometry",this);
    this->animal2->setDuration(1600);
    this->animal2->setStartValue(QRect(14,20,3,0));
    this->animal2->setKeyValueAt(0.5,QRect(14,0,3,20));
    this->animal2->setEndValue(QRect(14,20,3,0));

    this->animal2->setLoopCount(-1);
    this->animal2->start();

    this->animal3 = new QPropertyAnimation(ui->line3,"geometry",this);
    this->animal3->setDuration(1700);
    this->animal3->setStartValue(QRect(22,20,3,0));
    this->animal3->setKeyValueAt(0.5,QRect(22,0,3,20));
    this->animal3->setEndValue(QRect(22,20,3,0));

    this->animal3->setLoopCount(-1);
    this->animal3->start();

    this->animal4 = new QPropertyAnimation(ui->line4,"geometry",this);
    this->animal4->setDuration(1800);
    this->animal4->setStartValue(QRect(30,20,3,0));
    this->animal4->setKeyValueAt(0.5,QRect(30,0,3,20));
    this->animal4->setEndValue(QRect(30,20,3,0));

    this->animal4->setLoopCount(-1);
    this->animal4->start();

}

BTFrom::~BTFrom()
{
    delete ui;
}

void BTFrom::seticon(QString btIcon, QString content,int Id)
{
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(content);
    this->id = Id;
}

int BTFrom::GetId()
{
    return this->id;
}

void BTFrom::clearBackground()
{
    ui->btSytle->setStyleSheet("#btSytle:hover{\
                               background-color:#D8D8D8;}");
}

void BTFrom::showAnaimal(bool isShow)
{
    if (isShow)
    {
        ui->lineBox->show();
    }
    else
    {
        ui->lineBox->hide();
    }

}

void BTFrom::mousePressEvent(QMouseEvent *event)
{
    //1. 当鼠标按下的时候修改背景颜色
    ui->btSytle->setStyleSheet("#btSytle{background-color:rgb(30,206,154);}");

    //2. 当按钮按下的时候,需要切换bodyRight中的 page 页面
    emit BtClick(this->id);
}
